home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / squport.arc / SQIO.C < prev    next >
Text File  |  1985-06-16  |  896b  |  52 lines

  1. #include <stdio.h>
  2. #include "sqcom.h"
  3. #include "sq.h"
  4. #define ERROR -1
  5.  
  6. /* Get next byte from file and update checksum */
  7.  
  8. int
  9. getc_crc(ib)
  10. FILE *ib;
  11. {
  12.     int c;
  13.  
  14.     c = getc(ib);
  15.     if (c != EOF)
  16.         crc += c;        /* checksum */
  17.     return c;
  18. }
  19.  
  20. /* Output functions with error reporting */
  21.  
  22. static char obuf[128];
  23. static int oblen = 0;
  24.  
  25. putce(c,  iob)
  26. int c;
  27. FILE *iob;
  28. {
  29.     obuf[oblen++] = c;
  30.     if (oblen >= sizeof(obuf)) oflush(iob);
  31. }
  32.  
  33. putwe(w,  iob)
  34. int w;
  35. FILE *iob;
  36. {
  37.     obuf[oblen++] = w;
  38.     if (oblen >= sizeof(obuf)) oflush(iob);
  39.     obuf[oblen++] = w >> 8;
  40.     if (oblen >= sizeof(obuf)) oflush(iob);
  41. }
  42.  
  43. oflush(iob)                /* flush output buffer */
  44. FILE *iob;
  45. {
  46.     if (oblen && !fwrite(obuf, oblen, 1, iob)) {
  47.         printf("Error writing output file\n");
  48.         exit(1);
  49.     }
  50.     oblen = 0;
  51. }
  52.